<% content_for :content do %>

  <!-- widget grid -->
  <section id="widget-grid" class="">
  
    <!-- row -->
    <div class="row">
  
      <!-- NEW WIDGET START -->
      <article class="col-sm-12 col-md-12 col-lg-6">

        <!-- Widget ID (each widget will need unique ID)-->
        <div class="jarviswidget jarviswidget-color-blue" id="wid-id-1" data-widget-editbutton="false" data-widget-colorbutton="false" data-widget-deletebutton="false">
          <!-- widget options:
          usage: <div class="jarviswidget" id="wid-id-0" data-widget-editbutton="false">
  
          data-widget-colorbutton="false"
          data-widget-editbutton="false"
          data-widget-togglebutton="false"
          data-widget-deletebutton="false"
          data-widget-fullscreenbutton="false"
          data-widget-custombutton="false"
          data-widget-collapsed="true"
          data-widget-sortable="false"
  
          -->
          <header>
            <span class="widget-icon"> <i class="fa fa-sitemap"></i> </span>
            <h2>区域管理 </h2>
  
          </header>
  
          <!-- widget div-->
          <div>
  
            <!-- widget edit box -->
            <div class="jarviswidget-editbox">
              <!-- This area used as dropdown edit box -->
  
            </div>
            <!-- end widget edit box -->
  
            <!-- widget content -->
            <div class="widget-body">

              <div class="widget-body-toolbar bg-color-white">
  
                <div class="row">

                  <div class="col-sm-12 col-md-12">
                    
                    <%= link_to '<i class="fa fa-plus"></i> 添加省'.html_safe, new_admin_area_path(level: 'province',country_id: Country.first.id), class: "btn btn-default btn-sm", :remote => true %>
                  </div>

                </div>
  
              </div>


              <div class="tree smart-form">
                <ul>
                  <li>
                    <span><i class="fa fa-lg fa-folder-open"></i> 中国</span>
                    <ul>
                    <% Province.includes(:cities).all.each do |province| %>
                      <% if current_admin.can_see?(province) %>
                      <li id="area-province-<%= province.id %>">
                        <span>
                          <i class="fa fa-lg <%= province.cities.present? ? 'fa-plus-circle' : 'fa-minus-circle' %>"></i> 
                          <%= province.name %> 
                        </span>
                        <%= link_to "添加市", new_admin_area_path(level: 'city',province_id: province.id), :remote => true if current_admin.can?(controller: "admin/cities", action: :new) %>
                        <%= link_to '编辑', edit_admin_area_path(province, level: 'province'), remote: true if current_admin.can?(controller: "admin/provinces", action: :edit) %>
                        <%= link_to '删除', admin_area_path(province, level: 'province'), method: :delete, remote: true, confirm: '是否确定删除?' if current_admin.can?(controller: "admin/provinces", action: "destroy") %>
                        <ul>
                        <% province.cities.each do |city| %>
                          <% if current_admin.can_see?(city) %>
                          <li id="area-city-<%= city.id %>">
                            <span class="<%= ((@city && city.id == @city.id) ? 'current' : '')%>">
                            <i class="icon-leaf"></i>
                            <%= link_to city.name,admin_terminal_groups_path(city_id: city.id) %>
                            </span>
                            <%= link_to '编辑', edit_admin_area_path(city, level: 'city'), remote: true if current_admin.can?(controller: "admin/cities", action: :edit) %>
                            <%= link_to '删除', admin_area_path(city, level: 'city'), method: :delete, remote: true, confirm: '是否确定删除?' if current_admin.can?(controller: "admin/cities", action: :destroy) %>
                          </li>
                          <% end %>
                        <% end %>
                        </ul>
                      </li>
                      <% end %>
                    <% end %>
                    </ul>
                  </li>
                </ul>

              </div>

            </div>
            <!-- end widget content -->
  
          </div>
          <!-- end widget div -->
  
        </div>
        <!-- end widget -->
  
      </article>
      <!-- WIDGET END -->
  
    </div>
  
    <!-- end row -->
  
    <!-- row -->
  
    <div class="row">
  
    </div>
  
    <!-- end row -->
    
  </section>
  <!-- end widget grid -->
<% end %>